home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Language/OS - Multiplatform Resource Library
/
LANGUAGE OS.iso
/
cpp_libs
/
answrbok
/
6_3.lha
/
6_3
/
6_3c1.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-08-08
|
689b
|
33 lines
* Copyright (c) 1990 by AT&T Bell Telephone Laboratories, Incorporated. */
* The C++ Answer Book */
* Tony Hansen */
* All rights reserved. */
/ Assign something to a substring, version 1
/ Only allow equal length assignments.
include <string.h>
include <string.h>
/ substring = char*
ubstring& substring::operator=(char *cp)
if (len != strlen(cp))
error("lengths must match for assignment");
// disconnect string
if (str->p->n > 1)
{
str->p->n--;
struct srep *oldp = str->p;
str->p = new struct srep;
str->p->s = new char[strlen(oldp->s) + 1];
strcpy(str->p->s, oldp->s);
str->p->n = 1;
s = str->p->s + (s - oldp->s);
}
if (len > 0)
memcpy(s, cp, len);
return *this;